package com.example.projectmanagement.model.study;

import com.example.projectmanagement.model.User;
import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;

@Entity
@Table(name = "study_points_transaction")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
public class StudyPointsTransaction {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;

    @Column(name = "points")
    private Integer points; // 积分变化值（正数表示获得积分，负数表示消耗积分）

    @Column(name = "transaction_type")
    private String transactionType; // 积分获取类型：观看视频/完成课程/提问/回答被采纳/每日签到

    @Column(name = "description")
    private String description; // 描述

    @Column(name = "reference_id")
    private Long referenceId; // 关联ID（如课程ID、问题ID等）

    @CreatedDate
    @Column(name = "transaction_time")
    private LocalDateTime transactionTime;
}